<template>
	<view>
		<view class="scroll_header"></view>
			<scroll-view scroll-y="true" :style="{height: scrollHeight}">
				<view class="mt-5" v-if="u_loadmore">
					<u-loadmore status="loading" icon-type="circle" />
				</view>
				<view v-else>
				<view class="rounded-20 m-2 pl-3  bg-white" >
					<view class="d-flex border-bottom j-sb pr-2 py-3">
						<view class="">价格</view>
						<view class="d-flex j-center a-center">
							<input type="digit" value="" @focus="shop_focus" @blur="shop_blur" v-model="shop_price" class="text-right" placeholder-class="d-flex j-end" @input="shops" />
						</view>
					</view>
					<view class="d-flex j-sb pr-2 py-3">
						<view class="">成本价</view>
						<view class="d-flex j-center a-center">
							<input type="digit" @focus="cost_focus" @blur="cost_blur" v-model="cost_price" class="text-right" placeholder-class="d-flex j-end" @input="cost_input" />
						</view>
					</view>
				</view>
				<view class="rounded-20 m-2 pl-3  bg-white  clazz" @click="goodsVip">
					<view class="d-flex a-center j-sb pr-2 py-3 clazz">
						<view class="">会员价格</view>
						<view class="d-flex j-center a-center">
							<text class="text-light-muted mr-1">已设置</text>
							<u-icon name="arrow-right" color="#909399" size="30"></u-icon>
						</view>
					</view>		
				</view>
				<view class="rounded-20 m-2 pl-3  bg-white" >
					<view class="d-flex j-sb clazz a-center pr-2 py-3 border-bottom" @click="goodsMin">
						<view class="">最小起购数</view>
						<view class="d-flex j-center a-center">
							<text class="text-light-muted mr-1">{{special.minimum_info.is_minimum=='yes'?'已设置':'去设置'}}</text>
							<u-icon name="arrow-right" color="#909399" size="30"></u-icon>
						</view>
					</view>
					<view class="d-flex j-sb clazz a-center pr-2 py-3 border-bottom" @click="goodsStair">
						<view class="">阶梯价格</view>
						<view class="d-flex j-center a-center">
							<text class="text-light-muted mr-1">{{expert.volume_number.length==0?'去设置':'已设置'}}</text>
							<u-icon name="arrow-right" color="#909399" size="30"></u-icon>
						</view>
					</view>
				</view>
				
				<view class="rounded-20 m-2 clazz  pl-3  bg-white" >
					<view class="d-flex j-sb clazz a-center pr-2 py-3" @click="goodsRest">
						<view class="">其他信息</view>
						<view class="d-flex j-center a-center">
							<text class="text-light-muted mr-1">{{rest?'已设置':'去设置'}}</text>
							<u-icon name="arrow-right" color="#909399" size="30"></u-icon>
						</view>
					</view>		
				</view>
				</view>
			</scroll-view>
			<view class="bg-white py-2 w-100 foot btn">
				<button type="warn" @click="preserve">保存</button>
			</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				goods_id: 0, // 商品ID
				expert:"", // 商品详情
				shop_price:"", // 价钱
				special:"", // 高级改价信息
				cost_price:"", // 成本价
				scrollHeight:0,// 屏幕高度
				u_loadmore:true, // 加载中
			}
		},
		onReady() {
			let _this=this
			uni.getSystemInfo({
				success(resu) {
					const query = uni.createSelectorQuery()
					query.select('.scroll_header').boundingClientRect()
					query.select('.foot').boundingClientRect()
					console.log(resu)
					query.exec(function(res) {
						_this.scrollHeight = resu.windowHeight - res[0].top - res[1].bottom+ 'px';
					})
				}
			})
		},
		methods: {
			// 会员价格
			goodsVip(){
				uni.navigateTo({
					url:"/pages/goods-edit-expert-vip/goods-edit-expert-vip?goods_id="+this.goods_id
				})
			},
			// 最小起购数
			goodsMin(){
				uni.navigateTo({
					url:"/pages/goods-edit-expert-min/goods-edit-expert-min?goods_id="+this.goods_id
				})
			},
			// 阶梯价格
			goodsStair(){
				uni.navigateTo({
					url:"/pages/goods-edit-expert-stair/goods-edit-expert-stair?goods_id="+this.goods_id
				})
			},
			// 其他信息
			goodsRest(){
				uni.navigateTo({
					url:"/pages/goods-edit-expert-rest/goods-edit-expert-rest?goods_id="+this.goods_id
				})
			},
			// 修改价格
			shops(e){
				this.shop_price=e.detail.value
				console.log(e)
			},
			shop_focus(e){
				this.shop_price=""
			},
			shop_blur(e){
				if(e.detail.value==''){
					this.shop_price=this.expert.shop_price
				}
			},
			// 成本价格
			cost_input(e){
				this.cost_price=e.detail.value
			},
			cost_focus(e){
				this.cost_price=""
			},
			cost_blur(e){
				if(e.detail.value==''){
					this.cost_price=this.expert.cost_price
				}
			},
			// 保存
			preserve(){
				this.$H.post("admin/merchant/goods/price/updateAll",{
					goods_id:this.expert.goods_id,
					shop_price:this.shop_price.replace("￥",''),
					cost_price:this.cost_price.replace("￥",''),
				}).then(res=>{
					uni.navigateBack({
						delta:1
					})
				})
			}	
		},
		onLoad(e) {
			console.log(e)
			this.goods_id=e.goods_id
			this.$H.post("admin/merchant/goods/detail",{goods_id:e.goods_id}).then(res=>{
				this.expert=res.data
				this.market_price=this.expert.market_price
				this.shop_price=this.expert.shop_price
				this.cost_price=this.expert.cost_price
				this.u_loadmore=false 
			})
		},
		onShow() {
			this.$H.post("admin/merchant/goods/special/info",{goods_id:this.goods_id}).then(res=>{
				this.special=res.data
				console.log(res.data)
			})
			this.$H.post("admin/merchant/goods/detail",{goods_id:this.goods_id}).then(res=>{
				this.expert=res.data
			})
		}
	}
</script>
<style>
	.btn /deep/ button{
		width: 85%;
		border-radius: 50upx;
		background: linear-gradient(to right,#F31E3E,#FB4F37);
	}
	.preserve{
		height: 132upx; 
	}
</style>
